<?php
//Target Info Eco child theme functions
//
//                
//A function to get custom field image attachment...
//if there is none, use default image
function image_attachment($field, $width, $height) {
	global $post;
	$custom_field = get_post_meta($post->ID, $field, true);
	//default fallback URL and PATH
	$default_img = get_bloginfo('template_url').'/images/'.$field.'.png';
	$default_img_path = TEMPLATEPATH.'/images/'.$field.'.png';
	
	if($custom_field) { //if the user set a custom field
		echo '<img src="'.$custom_field.'" alt="'.get_the_title().'" width="'.$width.'" height="'.$height.'"/>';
	}
	elseif (file_exists($default_img_path)) { //if the fallback image exists
		//echo '<img src="'.$default_img.'" alt="'.get_the_title().'" width="'.$width.'" height="'.$height.'"/>';
	}
	else { //if fallback image does not exist, use a grey block div
		//echo '<div style="background: #CCC; width: '.$width.'px; height: '.$height.'px; color: #000; text-align: center; float: left;">No Image Available</div>';
	}
}

function prox_content_limit($max_char, $more_link_text = '...', $stripteaser = 0, $more_file = '') {
    $content = get_the_content($more_link_text, $stripteaser, $more_file);
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]&gt;', $content);
    

   if (strlen($_GET['p']) > 0) {
      echo $content;
      return;
   }
   if ($max_char == 0 ) {
       echo $content;
       return;
   }
   $content = strip_tags($content, '<a></a>');
   //get the page link
   $pos = preg_match('{<a([^>]*)>}',$content,$matches);
   if ($pos){
       $view_page = '<p>'.$matches[0].'View Full Article</a></p>';
       $content = preg_replace('{(<a)([^<]*)(</a>)}','',$content);  //get rid of links
   }
   if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
        $content = substr($content, 0, $espacio);
        $content = $content.$view_page;
        echo $content;
   }
   else {
      echo $content.$view_page;
   }
}

?>